using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace LiveStock.dataAccess
{
    /// <summary>
    /// Data Access Layer class for Evaluations table
    /// </summary>
    class EvaluationsData
    {
        private EvaluationsData() { }

        public static Evaluations.EvaluationsDataTable EvaluationsGetByRecommendationID(int recommendationID)
        {
            Evaluations.EvaluationsDataTable edt = new Evaluations.EvaluationsDataTable();
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationsGetByRecommendationID"))
            {
                cmd.Parameters.AddWithValue("RecommendationID", recommendationID);
                DBManager.FillDataTable(edt, cmd);
            }
            return edt;
        }

        public static int EvaluationInsert(Evaluations.EvaluationsRow er)
        {
            int ar = 0;
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationInsert"))
            {
                cmd.Parameters.AddWithValue("EvaluationSourceID", er.EvaluationSourceID);
                cmd.Parameters.AddWithValue("RecommendationID", er.RecommendationID);
                cmd.Parameters.AddWithValue("RatingTypeID", er.RatingTypeID);
                cmd.Parameters.AddWithValue("Description", er.Description);
                cmd.Parameters.AddWithValue("URL", er.URL);
                cmd.Parameters.AddWithValue("EvaluationDate", er.EvaluationDate);
                cmd.Parameters.AddWithValue("Rating", er.Rating);
                cmd.Parameters.AddWithValue("Title", er.Title);
                ar = DBManager.ExecuteNonQuery(cmd);
            }
            return ar;
        }

        public static Evaluations.EvaluationsDataTable EvaluationGetByID(int evaluationID)
        {
            Evaluations.EvaluationsDataTable edt = new Evaluations.EvaluationsDataTable();
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationGetByID"))
            {
                cmd.Parameters.AddWithValue("EvaluationID", evaluationID);
                DBManager.FillDataTable(edt, cmd);
            }
            return edt;
        }

        public static Evaluations.EvaluationsDataTable EvaluationGetByCompanyID(int companyID)
        {
            Evaluations.EvaluationsDataTable edt = new Evaluations.EvaluationsDataTable();
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationGetByCompanyID"))
            {
                cmd.Parameters.AddWithValue("CompanyID", companyID);
                DBManager.FillDataTable(edt, cmd);
            }
            return edt;
        }

        public static int EvaluationDeleteByID(int evaluationID)
        {
            int ar = 0;
            using (SqlCommand cmd = DBManager.GetCommand("EvaluationDeleteByID"))
            {
                cmd.Parameters.AddWithValue("EvaluationID", evaluationID);
                ar = DBManager.ExecuteNonQuery(cmd);
            }
            return ar;
        }
    }
}
